package demo1;

import java.util.concurrent.Callable;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-14
 * Time: 20:48
 */
public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog("旺财",2);
        Dog dog = (Dog) animal;
        dog.hunt();//向下转型
        System.out.println("=====================");
        /*Animal animal2 = new Cat("咪咪", 2);
        Dog dog2 = (Dog)animal2;
        Dog.hunt(); //不能向下转型*/
    }
    public static void func(Animal animal){
        animal.eat();
    }
    //多态
    public static void main2(String[] args) {
        Dog dog = new Dog("旺财", 2);
        func(dog);
        System.out.println("=================");
        Cat cat = new Cat("咪咪", 3);
        func(cat);
    }
    public static void main1(String[] args) {
        Animal animal = new Dog("旺财", 2);
        animal.eat();//动态绑定
    }
}
